/*
 * 文件名：LocalCarTypeServiceImpl.java	 
 * 时     间：下午6:30:19
 * 作     者：Administrator       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cz073586.tools.util.Tools;
import com.local.dao.mapers.LocalChargeBytimeTypeMapper;
import com.local.model.LocalChargeBytimeType;
import com.local.model.LocalChargeBytimeTypeExample;
import com.local.service.face.LocalChargeByTimeTypeService;
import com.qianhai.common.dao.face.BaseMapper;
import com.qianhai.common.exception.BaseException;
import com.qianhai.common.service.impl.BaseServiceImpl;
import com.qianhai.common.utils.UUIDGenerateUtil;

/**
 * 类描述:这里是类描述
 * 
 * @ClassName: LocalCarTypeServiceImpl
 * @author Administrator
 * @date 2016年4月17日 下午6:30:19
 */
@Service
public class LocalChargeByTimeTypeTypeServiceImpl extends
		BaseServiceImpl<LocalChargeBytimeTypeExample, LocalChargeBytimeType, String> implements
		LocalChargeByTimeTypeService
{
	@Autowired
	private LocalChargeBytimeTypeMapper localChargeBytimeTypeMapper;
	
	@Override
	public Integer addCarType(LocalChargeBytimeType lb) throws BaseException
	{
		try
		{
			if(Tools.isEmpty(lb.getName())){
				throw new BaseException("50000-00011-00002");
			}
			// 判断车型名重复
			if (!Tools.isEmpty(lb.getName()))
			{
				LocalChargeBytimeTypeExample ex = new LocalChargeBytimeTypeExample();
				ex.or().andNameEqualTo(lb.getName());
				List<LocalChargeBytimeType> list = localChargeBytimeTypeMapper.selectByCondition(ex);
				if (!list.isEmpty()&&!Tools.isEmpty(lb.getUuid()))
				{
					if(!list.get(0).getUuid().equalsIgnoreCase(lb.getUuid())){
						//修改时重复
						throw new BaseException("50000-00011-00001");
					}
				}else if(!list.isEmpty()&&Tools.isEmpty(lb.getUuid())){
					//增加重复
					throw new BaseException("50000-00011-00001");
				}
			}
			if(!Tools.isEmpty(lb)&&!Tools.isEmpty(lb.getUuid())){
				localChargeBytimeTypeMapper.updateByPrimaryKey(lb);
			}else{
				lb.setUuid(UUIDGenerateUtil.generate());
				localChargeBytimeTypeMapper.insertSelective(lb);
			}
		} catch (Throwable t)
		{
			log.error(t.getMessage(), t);
			throw new BaseException(t.getMessage());
		}
		return null;
	}
	
	@Override
	public Integer modifyCarType(LocalChargeBytimeType lb) throws BaseException
	{
		try
		{
			
			// 判断车型名重复
			if (!Tools.isEmpty(lb.getName()))
			{
				LocalChargeBytimeTypeExample ex = new LocalChargeBytimeTypeExample();
				ex.or().andNameEqualTo(lb.getName())
						.andUuidNotEqualTo(lb.getUuid());
				List<LocalChargeBytimeType> list = localChargeBytimeTypeMapper.selectByCondition(ex);
				if (!list.isEmpty())
				{
					throw new BaseException("50000-00011-00001");
				}
			}
			localChargeBytimeTypeMapper.updateByPrimaryKeySelective(lb);
		} catch (Throwable t)
		{
			log.error(t.getMessage(), t);
			throw new BaseException(t.getMessage());
		}
		return null;
	}
	
	

	@Override
	public LocalChargeBytimeType queryByUuid(LocalChargeBytimeType lb) throws BaseException
	{
		// TODO Auto-generated method stub
		if(!Tools.isEmpty(lb)&&!Tools.isEmpty(lb.getUuid())){
			return localChargeBytimeTypeMapper.selectByPrimaryKey(lb.getUuid());
		}
		return null;
	}

	@Override
	public BaseMapper<LocalChargeBytimeTypeExample, LocalChargeBytimeType, String> getMapper()
	{
		// TODO Auto-generated method stub
		return localChargeBytimeTypeMapper;
	}

	@Override
	public List<LocalChargeBytimeType> queryAllCar()
	{
		// TODO Auto-generated method stub
		List<LocalChargeBytimeType> list=localChargeBytimeTypeMapper.queryAllCar();
		return list;
	}
	
}
